//
//  DTTabBarController.m
//  Dantang 9.4
//
//  Created by 伍银荣 on 2017/9/7.
//  Copyright © 2017年 WYR. All rights reserved.
//

#import "DTTabBarController.h"
#import "ClassViewController.h"
#import "MyViewController.h"
#import "ItemViewController.h"
#import "HomeViewController.h"
#import "DTNavigationController.h"

@interface DTTabBarController ()

@end

@implementation DTTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //首页
    HomeViewController *homeVC = [[HomeViewController alloc]init];
    //添加一个子视图控制器
    [self addChildViewController:homeVC imageName:@"TabBar_home_23x23_" selectedImage:@"TabBar_home_23x23_selected" title:@"首页"];
    
    

    
    //分类
    [self addChildViewController:[ClassViewController new] imageName:@"TabBar_category_23x23_" selectedImage:@"TabBar_category_23x23_selected" title:@"分类"];
    
    //单品
    [self addChildViewController:[ItemViewController new] imageName:@"TabBar_gift_23x23_" selectedImage:@"TabBar_gift_23x23_selected" title:@"单品"];
    
    //个人
    [self addChildViewController:[MyViewController new] imageName:@"TabBar_me_boy_23x23_" selectedImage:@"TabBar_me_boy_23x23_selected" title:@"个人"];
    
    
    
    
}

//给tabbar添加子视图控制器方法
//子视图控制器、默认tab图片、点击后图片、文字
-(void)addChildViewController:(UIViewController *)childController imageName:(NSString *)imageName selectedImage:(NSString *)selectedImageName title:(NSString *)title
{
    childController.title = title;
    childController.tabBarItem.image = [UIImage mr_imageOriginalWithName:imageName];
    childController.tabBarItem.selectedImage = [UIImage mr_imageOriginalWithName:selectedImageName];
    NSDictionary *dict = @{NSForegroundColorAttributeName:MRGlobalBg, NSFontAttributeName: [UIFont systemFontOfSize:16]};
    [childController.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];

    //包装一个导航栏控制器，添加导航条为tab子控制器
    DTNavigationController *nav = [[DTNavigationController alloc]initWithRootViewController:childController];
    [self addChildViewController:nav];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
